{% extends "base.html" %}

{% block content %}
<div class="container">
    <h2 class="mb-4">安全检查管理</h2>
    
    <div class="card mb-4">
        <div class="card-body">
            <form method="GET" class="row g-3">
                <div class="col-md-3">
                    <input type="text" class="form-control" name="product_name" placeholder="产品名称" value="{{ product_name }}">
                </div>
                <div class="col-md-3">
                    <input type="text" class="form-control" name="batch_number" placeholder="批次号" value="{{ batch_number }}">
                </div>
                <div class="col-md-2">
                    <select class="form-select" name="inspection_type">
                        <option value="">检查类型</option>
                        <option value="routine" {% if inspection_type == 'routine' %}selected{% endif %}>常规检查</option>
                        <option value="special" {% if inspection_type == 'special' %}selected{% endif %}>专项检查</option>
                        <option value="followup" {% if inspection_type == 'followup' %}selected{% endif %}>跟进检查</option>
                    </select>
                </div>
                <div class="col-md-2">
                    <select class="form-select" name="result">
                        <option value="">检查结果</option>
                        <option value="passed" {% if result == 'passed' %}selected{% endif %}>通过</option>
                        <option value="failed" {% if result == 'failed' %}selected{% endif %}>不通过</option>
                        <option value="pending" {% if result == 'pending' %}selected{% endif %}>待定</option>
                    </select>
                </div>
                <div class="col-md-2">
                    <button type="submit" class="btn btn-primary w-100">搜索</button>
                </div>
            </form>
        </div>
    </div>

    <div class="mb-3">
        <a href="{{ url_for('safety.inspection_add') }}" class="btn btn-success">
            <i class="fas fa-plus"></i> 新增检查
        </a>
    </div>

    <div class="table-responsive">
        <table class="table table-striped table-hover">
            <thead>
                <tr>
                    <th>检查编号</th>
                    <th>产品名称</th>
                    <th>批次号</th>
                    <th>检查类型</th>
                    <th>检查人</th>
                    <th>检查时间</th>
                    <th>检查结果</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for inspection in inspections %}
                <tr>
                    <td>{{ inspection.inspection_no }}</td>
                    <td>{{ inspection.product_name }}</td>
                    <td>{{ inspection.batch_number }}</td>
                    <td>
                        {% if inspection.inspection_type == 'routine' %}
                            常规检查
                        {% elif inspection.inspection_type == 'special' %}
                            专项检查
                        {% else %}
                            跟进检查
                        {% endif %}
                    </td>
                    <td>{{ inspection.inspector }}</td>
                    <td>{{ inspection.inspection_date.strftime('%Y-%m-%d %H:%M') }}</td>
                    <td>
                        {% if inspection.result == 'passed' %}
                            <span class="badge bg-success">通过</span>
                        {% elif inspection.result == 'failed' %}
                            <span class="badge bg-danger">不通过</span>
                        {% else %}
                            <span class="badge bg-warning">待定</span>
                        {% endif %}
                    </td>
                    <td>
                        <a href="{{ url_for('safety.inspection_edit', id=inspection.id) }}" class="btn btn-sm btn-primary">
                            <i class="fas fa-edit"></i> 编辑
                        </a>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    {% if pagination.pages > 1 %}
    <nav aria-label="Page navigation">
        <ul class="pagination justify-content-center">
            {% for page in pagination.iter_pages() %}
                {% if page %}
                    <li class="page-item {% if page == pagination.page %}active{% endif %}">
                        <a class="page-link" href="{{ url_for('safety.inspection_list', page=page, product_name=product_name, batch_number=batch_number, inspection_type=inspection_type, result=result) }}">{{ page }}</a>
                    </li>
                {% else %}
                    <li class="page-item disabled"><span class="page-link">...</span></li>
                {% endif %}
            {% endfor %}
        </ul>
    </nav>
    {% endif %}
</div>
{% endblock %} 